﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BS.Infra
{
    public class ApiResult
    {
        public bool IsSuc { get; set; }

        public string Msg { get; set; }

        public object? Data { get; set; }

        public ApiResultCode Code { get; set; }

        private ApiResult(bool isSuc, string msg, object? data,ApiResultCode code)
        {
            IsSuc = isSuc;
            Msg = msg;
            Data = data;
            Code = code;
        }
        /// <summary>
        /// 成功的请求
        /// </summary>
        /// <param name="data"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ApiResult Ok(object? data = null,string msg="操作成功")
        {
            return new ApiResult(true, msg, data, ApiResultCode.Success);
        }
        /// <summary>
        /// 失败的请求
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ApiResult Fail(string msg="操作失败")
        {
            return new ApiResult(false, msg, null, ApiResultCode.Fail);
        }
    }
}
public enum ApiResultCode
{
    Success=200,

    Fail=500,

    ErrCount=502,

    Fi=505
}